<?php 
session_start();
function dateFormatBrazil($date){
		//recebe o parâmetro e armazena em um array separado por -
		$date = explode('-', $date);
		$date = $date[2].'/'.$date[1].'/'.$date[0];
		//retorna a string com a data na ordem correta e formatada
		return $date;
	}

?>
<?php
$agent = strtolower($_SERVER["HTTP_USER_AGENT"]);
if(!strstr($agent, "firefox") && !strstr($agent, "msie")) {
	// Mostra seu conteudo 
} else {
	// Erro navegador FireFox ou IE bloquedao ...
	header('location:bloqueia_firefoxie.php');
}
?>
<script language='JavaScript' charset="utf-8">
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;   
    if((tecla>47 && tecla<58)) return true;
    else{
    	if (tecla==8 || tecla==0) return true;
	else  return false;
    }
}

function valida() {
	solicitante = document.form1.solicitante.value;
	matricula = document.form1.matricula.value;
	cargo = document.form1.cargo.value;
	email = document.form1.email.value;
	setor = document.form1.setor.value;
	ramal = document.form1.ramal.value;
	veiculo = document.form1.veiculo.value;
	data_ida = document.form1.data_ida.value;
	hora_partida = document.form1.hora_partida.value;
	data_volta = document.form1.data_volta.value;
	hora_chegada = document.form1.hora_chegada.value;
	roteiro = document.form1.roteiro.value;
	finalidade = document.form1.finalidade.value;
	passageiros = document.form1.passageiros.value;
		
	if(solicitante==""){
		alert("Por favor, preencha o campo solicitante.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(matricula==""){
		alert("Por favor, preencha o campo de matrícula.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(matricula.length < 7){
		alert("Atenção: Matrícula inválida.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	/*else if(data==0000-00-00){
		alert("Por favor, preencha a data.");
		document.forms['form1'].onsubmit = function(){return false;};
	}*/
	else if(cargo==""){
		alert("Por favor, preencha o cargo.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(email==""){
		alert("Por favor, preencha o email.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(setor==""){
		alert("Por favor, preencha o setor.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(ramal==""){
		alert("Por favor, preencha o ramal.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(veiculo==""){
		alert("Por favor, selecione um veículo.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(data_ida==0000-00-00){
		alert("Por favor, preencha a data de partida.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(hora_partida==""){
		alert("Por favor, selecione um horário de partida.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(data_volta==0000-00-00){
		alert("Por favor, preencha a data de chegada.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(data_volta < data_ida){
		alert("Atenção, data de volta menor que data de partida.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(hora_chegada==""){
		alert("Por favor, selecione um horário de chegada.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(roteiro==""){
		alert("Por favor, preencha o roteiro.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(finalidade==""){
		alert("Por favor, preencha a finalidade.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else if(passageiros==""){
		alert("Por favor, preencha os passageiros.");
		document.forms['form1'].onsubmit = function(){return false;};
	}
	else{
		document.forms['form1'].onsubmit = function(){return true;};
	}
	
}

function limpaForm(){
	document.form1.solicitante.value = "";
	document.form1.matricula.value = "";
	document.form1.cargo.value = "";
	document.form1.email.value = "";
	document.form1.setor.value = "";
	document.form1.ramal.value = "";
	document.form1.veiculo.value = "";
	document.form1.reparo.value = "";
	document.form1.data_ida.value = "";
	document.form1.hora_partida = "";
	document.form1.data_volta.value = "";
	document.form1.hora_chegada = "";
	document.form1.roteiro.value = "";
	document.form1.finalidade.value = "";
	document.form1.passageiros.value = "";
}
</script>

<!DOCTYPE html>
<html lang="en">
<head>
	
	<script language="JavaScript">
		window.onload = function(){
		document.form1.solicitante.value = "";
		document.form1.matricula.value = "";
		document.form1.cargo.value = "";
		document.form1.email.value = "";
		document.form1.setor.value = "";
		document.form1.ramal.value = "";
		document.form1.veiculo.value = "";
		document.form1.data_ida.value = "";
		document.form1.hora_partida = "";
		document.form1.data_volta.value = "";
		document.form1.hora_chegada = "";
		document.form1.roteiro.value = "";
		document.form1.finalidade.value = "";
		document.form1.passageiros.value = "";
	}
	</script>

	
  <meta charset="utf-8">
  <title>Requerimento de Veículo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="">
	<link href="css/bootstrap.min.css" rel="stylesheet">
	<link href="css/style.css" rel="stylesheet">

  <!-- Fav and touch icons -->
  <link rel="apple-touch-icon-precomposed" sizes="144x144" href="img/apple-touch-icon-144-precomposed.png">
  <link rel="apple-touch-icon-precomposed" sizes="114x114" href="img/apple-touch-icon-114-precomposed.png">
  <link rel="apple-touch-icon-precomposed" sizes="72x72" href="img/apple-touch-icon-72-precomposed.png">
  <link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-57-precomposed.png">
  <link rel="shortcut icon" href="img/favicon.ico">
	<script type="text/javascript" src="js/jquery.min.js"></script>
	<script type="text/javascript" src="js/bootstrap.min.js"></script>
	<script type="text/javascript" src="js/scripts.js"></script>
</head>

<body>
<div class="panel panel-default">
				<div class="panel-heading">
					<h3 class="panel-title">
						<span class="glyphicon glyphicon-user"></span> <strong>Solicitação de Veículos</strong>
					</h3>
				</div>
				<div class="panel-body">
			<form role="form" class="form-horizontal" method="POST" name="form1" action="controller/controller.php" onsubmit="return limpaForm();">
			
				<input type="hidden" name="acao" value="incluir_veiculo">
				<!-- 	* CÓDIGO NOVO 
						* ESTE PEDAÇO DE CÓDIGO GERA A TABELA NA HORA DE VERIFICAR
						* A COMPATIBILIDADE DE HORÁRIO NA LOCAÇÃO DE VEÍCULO.
				-->
				<?php 
					//session_start(); ---> ESTÁ NO INÍCIO DO ARQUIVO
					if(isset ($_SESSION['dados'])){
						echo "<font color='red'><label>Incompatibilidade de veículo e/ou data/horário.</label></font>";
						$data = $_SESSION['dados'];
				?>
				<table class="table table-hover lista-servico" align="center">
					<thead>
					<tr>
						<th>Veículo</th>
						<th>Saída</th>
						<th>Hora</th>
						<th>Chegada</th>
						<th>Hora</th>
					</tr>
				</thead>
				<tbody>
				<?php
						foreach($data as $dados){
							echo '<tr>';
								echo '<td>'.$dados['veiculo'].'</td>';
								
								list( $date, $time ) = explode( ' ', $dados['data_hora_ida']);
								$date = dateFormatBrazil($date);
								list($time, $time2, $time3) = explode(':',$time);
								$time = $time.':'.$time2;
								echo '<td>'.$date.'</td>';
								echo '<td>'.$time.'</td>';
								list( $date, $time ) = explode( ' ', $dados['data_hora_volta']);
								$date = dateFormatBrazil($date);
								list($time, $time2, $time3) = explode(':',$time);
								$time = $time.':'.$time2;
								echo '<td>'.$date.'</td>';
								echo '<td>'.$time.'</td>';
							echo '</tr>';
						}
						session_destroy(); // DESTRUINDO A SEÇÃO
					}
					else{
						
					}
				?>
				</tbody>
				</table>
				<!-- FIM CÓDIGO NOVO -->
				<div class="form-group">
					<label class="col-sm-2 control-label">Solicitante</label>
					<div class="col-sm-7">
						<input type="text" class="form-control" name="solicitante" maxlength="100" />
					</div>
					<label class="col-sm-1 control-label">Matrícula</label>
					<div class="col-sm-2">
						<input type="text" class="form-control" name="matricula" maxlength="8" onkeypress='return SomenteNumero(event)'>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Cargo</label>
					<div class="col-sm-3">
						<input type="text" class="form-control" name="cargo" maxlength="50">
					</div>
					<label class="col-sm-1 control-label" for="exampleInputEmail1">Email</label>
					<div class="col-sm-6">
						<input type="email" class="form-control" id="exampleInputEmail1" name="email" />
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Setor</label>
					<div class="col-sm-3">
						<input type="text" class="form-control" name="setor" maxlength="50">
					</div>
					<label class="col-sm-1 control-label">Ramal</label>
					<div class="col-sm-6">
						<input type="text" class="form-control" name="ramal" maxlength="4" onkeypress='return SomenteNumero(event)'/>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Veículo</label>
					<div class="col-sm-3">
						<select class="form-control" name="veiculo">
							<option value=""></option>
							<option value="gol">Gol</option>
							<option value="siena">Siena</option>
							<option value="onibus">Ônibus</option>
							<option value="van">Van</option>
							<option value="caminhao">Caminhão</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Data de Partida</label>
					<div class="col-sm-4">
						<input type="date" class="form-control" name="data_ida">
					</div>
					<label class="col-sm-2 control-label">Horário de Partida</label>
					<div class="col-sm-4">
					<select class="form-control span2" name="hora_partida">
						<option value=""></option>
						<option value="01:00">01:00</option>
						<option value="02:00">02:00</option>
						<option value="03:00">03:00</option>
						<option value="04:00">04:00</option>
						<option value="05:00">05:00</option>
						<option value="06:00">06:00</option>
						<option value="07:00">07:00</option>
						<option value="08:00">08:00</option>
						<option value="09:00">09:00</option>
						<option value="10:00">10:00</option>
						<option value="11:00">11:00</option>
						<option value="12:00">12:00</option>
						<option value="13:00">13:00</option>
						<option value="14:00">14:00</option>
						<option value="15:00">15:00</option>
						<option value="16:00">16:00</option>
						<option value="17:00">17:00</option>
						<option value="18:00">18:00</option>
						<option value="19:00">19:00</option>
						<option value="20:00">20:00</option>
						<option value="21:00">21:00</option>
						<option value="22:00">22:00</option>
						<option value="23:00">23:00</option>
						<option value="24:00">24:00</option>
					</select>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Data de Chegada</label>
					<div class="col-sm-4">
						<input type="date" class="form-control" name="data_volta">
					</div>
					<label class="col-sm-2 control-label">Horário de Chegada</label>
					<div class="col-sm-4">
						<select class="form-control span2" name="hora_chegada">
							<option value=""></option>
							<option value="01:00">01:00</option>
							<option value="02:00">02:00</option>
							<option value="03:00">03:00</option>
							<option value="04:00">04:00</option>
							<option value="05:00">05:00</option>
							<option value="06:00">06:00</option>
							<option value="07:00">07:00</option>
							<option value="08:00">08:00</option>
							<option value="09:00">09:00</option>
							<option value="10:00">10:00</option>
							<option value="11:00">11:00</option>
							<option value="12:00">12:00</option>
							<option value="13:00">13:00</option>
							<option value="14:00">14:00</option>
							<option value="15:00">15:00</option>
							<option value="16:00">16:00</option>
							<option value="17:00">17:00</option>
							<option value="18:00">18:00</option>
							<option value="19:00">19:00</option>
							<option value="20:00">20:00</option>
							<option value="21:00">21:00</option>
							<option value="22:00">22:00</option>
							<option value="23:00">23:00</option>
							<option value="24:00">24:00</option>
						</select>
					</div>
					<!--<a href="#" onClick="popup();">Checar Disponibilidade</a>-->
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Roteiro</label>
					<div class="col-sm-10">
						<input type="text" class="form-control" name="roteiro" maxlength="50">
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">Finalidade</label>
					<div class="col-sm-4">
						<input type="text" class="form-control" name="finalidade" maxlength="50">
					</div>
					<label class="col-sm-3 control-label">Quantidade de Passageiros</label>
					<div class="col-sm-3">
						<input type="text" class="form-control" name="passageiros" maxlength="3" onkeypress='return SomenteNumero(event)'>
					</div>
				</div>
				<div class="form-group col-sm-3 text-center">
					<button type="submit" class="btn btn-success"  onClick="valida();">Solicitar</button>
				</div>
			</form>
				</div>
	<div class="panel-footer">
					<small><p class="text-right text-muted">Desenvolvido pela <a href="http://www.ifsertao-pe.edu.br/dgti" target="_blank" title="Coordenação de Tecnologia da Informação">CTI</a></p></small>
	</div>
</div>
</body>
</html>